﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace QLTV_V2.frm
{
    public partial class frmCauHinh : DevComponents.DotNetBar.Office2007Form
    {
        public byte cf=0;
        public frmCauHinh()
        {
            InitializeComponent();
        }

        private void frmCauHinh_Load(object sender, EventArgs e)
        {

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
                AppSettingsSection section = config.GetSection("appSettings") as AppSettingsSection;
                section.SectionInformation.UnprotectSection();
                config.Save();
                Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                _config.AppSettings.Settings["Server"].Value = txtServer.Text;
                _config.AppSettings.Settings["Database"].Value = txtData.Text;
                _config.AppSettings.Settings["Username"].Value = txtUser.Text;
                _config.AppSettings.Settings["Password"].Value = txtPass.Text;
                _config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");
                section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
                config.Save();
                cf = 1;
                txtServer.Clear();
                txtData.Clear();
                txtUser.Clear();
                txtPass.Clear();
                MessageBox.Show("Cấu hình thành công!", "Thông báo!");
                this.Close();
            }
            catch
            { 
            
            }
        }
    }
}
